/**
 * @description shop controll
 * @author boen
 */

const Shop = require('../models/Shop')
const Product = require('../models/Product')

/**
 * 获取近热门店铺列表
 * @returns 
 */
async function getHotList() {
    const hotList = await Shop.find().sort({
        _id: -1
    })
    return hotList
}

/**
 * 获取商店详情
 * @param {string} id id
 * @returns 
 */
async function getShopInfo(id) {
    const shopInfo = await Shop.findById(id)
    return shopInfo
}

/**
 * 查询某个商店的商品列表
 * @param {string} shopId 商店id
 * @param {string} tab 分类
 * @returns 
 */
async function getProductsByShopId(shopId, tab="all") {
    const productList = await Product.find({
        shopId,
        tabs: {
            $in: tab
        }
    })
    return productList
}

module.exports = {
    getHotList,
    getShopInfo,
    getProductsByShopId
}